﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace BackgroundWorkerEx
{
    public delegate void StepCaptionChanged(BackgroundWorkerEx sender);

    public class BackgroundWorkerEx : BackgroundWorker
    {
        /// <summary>
        /// для служебного использования
        /// </summary>
        private object tag;
        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        /// <summary>
        /// событие изменения строки состояния
        /// </summary>
        public event StepCaptionChanged OnCaptionChanged;

        private void doCaptionChanged()
        {
            if (OnCaptionChanged != null)
                OnCaptionChanged(this);
        }

        /// <summary>
        /// строка состояния (для визаулизации)
        /// </summary>

        private string stepCaption="";
        private string getCaption
        {
            get
            {
                if (string.IsNullOrEmpty(stepCaption)) return "";
                else return stepCaption;
            }
        }
        public string StepCaption
        {
            get { return getCaption; }
            set
            {
                if ((string.IsNullOrEmpty(value) && getCaption != "") ||
                    (value != getCaption))
                {
                    stepCaption = value;
                    doCaptionChanged();
                }
            }
        }

        
    }
}
